Skip to content

Conversation

@halter73
Copy link
Contributor

So far, I'm only using the XunitLoggerProvider in SseServerIntegrationTests.cs and ClientIntegrationTests.cs since those previously logged to the console which can be hard to see when using the xunit test runner. After this change, you can easily see logs in the test runner like this.

Logs in VS Test Explorer Window

We can probably integrate this in more places, and that should be easier to do going forward with the XunitLoggerProvider and LoggedTest base class.

@stephentoub
Copy link
Contributor

We can probably integrate this in more places

Which it be much more work to just consistently use it everywhere now?

@halter73
Copy link
Contributor Author

It's not much more work to use it in places where we are currently using NullLoggerFactory.Instance. It's harder in places where we're mocking the ILoggerFactory. I'll try adding logging to the tests using NullLoggerFactory.Instance before merging.

@stephentoub
Copy link
Contributor

It's not much more work to use it in places where we are currently using NullLoggerFactory.Instance. It's harder in places where we're mocking the ILoggerFactory. I'll try adding logging to the tests using NullLoggerFactory.Instance before merging.

Do we actually need to mock it? Seems like we could always just pass in the xunit logger. I don't know what the value is of mocking the logger, when we could either use a null logger or a test one.

@halter73
Copy link
Contributor Author

Do we actually need to mock it?

You're right. We don't. I assumed the mocks were being used to verify certain logs were emitted. If that were the case, it would be less trivial to updated it to also use the xunit logger. But it turns out, the mocks were used as a inconvenient substitute for NullLoggerFactory.Instance and were easy to replace.

I've not updated every test that provides an ILoggerFactory to be a LoggedTest that uses the xunit logger. I think this should now be good to merge.

@stephentoub stephentoub merged commit 60ea96a into modelcontextprotocol:main Mar 25, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants